package com.config;

import com.controller.UsersController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.model.Users;

public class Config extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		loadPropertyFile("conf.properties"); // 加载配置文件
	}

	@Override
	public void configRoute(Routes me) {
			me.add("/users", UsersController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		// 读取配置文件中的内容
		C3p0Plugin cp = new C3p0Plugin(getProperty("url"),
				getProperty("username"), getProperty("password"));
		me.add(cp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		me.add(arp);
		arp.setDialect(new MysqlDialect()); // 设置数据库方言
		arp.addMapping("users", Users.class); // 表名与实体类名之间的映射关系
		arp.setShowSql(true); // 设置数据库显示SQL语句
	}

	@Override
	public void configInterceptor(Interceptors me) {

	}

	@Override
	public void configHandler(Handlers me) {

	}

}
